/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ejb.facade;

import entities.Categoria;
import entities.*;
import java.util.*;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author sflesca
 */
@Stateless
public class ProdottoFacade extends AbstractFacade<Prodotto> implements ProdottoFacadeLocal {
    @PersistenceContext(unitName = "EsempioNegozioPSW2015-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }
    
    

    public ProdottoFacade() {
        super(Prodotto.class);
    }

    @Override
    public List<Prodotto> getProdottiDiCategoria(Categoria categoria, int inizio, int numero) {
        Query q = em.createNamedQuery("Prodotto.findCat");
        q.setParameter("cat", categoria);
        return q.setFirstResult(inizio).setMaxResults(numero).getResultList();
    }
    
}
